package com.ruoyi.food.serviceImpl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ruoyi.food.controller.TEnterpriseController;
import com.ruoyi.food.mapper.TActOrderMapper;
import com.ruoyi.food.mapper.TCancelVerificationMapper;
import com.ruoyi.food.mapper.TEnterpriseMapper;
import com.ruoyi.food.object.TActOrder;
import com.ruoyi.food.object.TCancelVerification;
import com.ruoyi.food.object.TEnterprise;
import com.ruoyi.food.service.TCancelVerService;

@Service
@Transactional
public class TCancelVerServiceImpl implements TCancelVerService {

	@Autowired
	private TCancelVerificationMapper tCancelVerMapper;
	
	@Autowired
	private TActOrderMapper tActOrderMapper;
	
	@Autowired
	private TEnterpriseMapper tEnterpriseMapper;
	
	@Override
	public List<TCancelVerification> findCancleVerByCon(TCancelVerification tCancelVerification) {
		// TODO Auto-generated method stub
		List<TCancelVerification> list=tCancelVerMapper.selectCanceByCon(tCancelVerification);
		return list;
	}

	@Override
	public void saveCancleVer(TCancelVerification tCancelVerification,TActOrder actOrder) {
		// TODO Auto-generated method stub
		tCancelVerMapper.insertTCancelVer(tCancelVerification);
		//更新订单表的核销时间
		tActOrderMapper.updatehxTime(tCancelVerification.getHxTime(), actOrder.getOrderId(),tCancelVerification.getEnterpriseId());
		TEnterprise tEnterprise=tEnterpriseMapper.selectTenterpriseById(tCancelVerification.getEnterpriseId());
		if(tEnterprise.getStockNum()>0) {
			tEnterpriseMapper.updateStockNumById(tEnterprise.getEnterpriseId(), tEnterprise.getStockNum()-1);
		}
		
		
	}

	@Override
	public List<TCancelVerification> findCancleVerByList(String string) {
		// TODO Auto-generated method stub
		return tCancelVerMapper.selectListAndNum(string);
	}

}
